package com.example.jeong.yuejian10.Adapter;



import android.content.Context;

import android.support.v7.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.jeong.yuejian10.Bean.ProBean;
import com.example.jeong.yuejian10.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.jeong.yuejian10.constant.Constant.USER_PHOTO_URL;


public class ProConsultListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;

    private LayoutInflater mLayoutInflatera;

    public ProConsultListAdapter(Context mContext,List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflatera = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflatera.from(parent.getContext())
                .inflate(R.layout.cardview_proconsult, parent, false);
        return new ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ProBean entity = (ProBean) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.userName.setText(entity.getU_name());
        viewHolder.consultInfo.setText(entity.getConsultinfo());
        viewHolder.Time.setText(entity.getConsult_time());

        //  Log.d("w","consultInfo");
        String UserPic = USER_PHOTO_URL+entity.getU_pic();
        Picasso.with(mContext).load(UserPic).into(viewHolder.userPic);
        if (viewHolder.userPic.getDrawable()==null){
            viewHolder.userPic.setImageResource(R.drawable.ic_add);
        }
        //点击item跳转
//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Bundle bundle = new Bundle();
//                bundle.putInt("pm_id",entity.getPm_id());
//                bundle.putInt("u_id",entity.getU_id());
//               // Log.d("o","u_id");
//                bundle.putInt("cp_id",entity.getCp_id());
//                bundle.putString("pc_name",entity.getPc_name());
//                bundle.putString("pc_time",entity.getPc_time());
////                Intent intent=new Intent(mContext,ProDetailActivity.class);
////                intent.putExtras(bundle);
////                mContext.startActivity(intent);
//
//            }
//        });

    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView userPic;
        TextView Time;
        TextView userName;
        TextView consultInfo;

        public ViewHolder(View itemView){
            super(itemView);
            userName = (TextView) itemView.findViewById(R.id.username);
            consultInfo = (TextView) itemView.findViewById(R.id.coninfo);
            Time = (TextView) itemView.findViewById(R.id.contime);
            userPic = (ImageView) itemView.findViewById(R.id.userpic);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}

